package cn.icanci.loopstack.bic.biz.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import cn.icanci.loopstack.bic.biz.mapper.UnitViewSnapshotIndexMapper;
import cn.icanci.loopstack.bic.biz.service.UnitViewSnapshotIndexService;
import cn.icanci.loopstack.bic.common.model.snapshot.UnitViewSnapshotIndexVO;
import cn.icanci.loopstack.bic.dal.mongo.common.PageList;
import cn.icanci.loopstack.bic.dal.mongo.daointerface.UnitViewSnapshotIndexDAO;
import cn.icanci.loopstack.bic.dal.mongo.dateobject.UnitViewSnapshotIndexDO;

/**
 * @author icanci
 * @since 1.0 Created in 2023/09/20 21:45
 */
@Service
public class UnitViewSnapshotIndexServiceImpl implements UnitViewSnapshotIndexService {

    @Resource
    private UnitViewSnapshotIndexDAO    unitViewSnapshotIndexDAO;
    @Resource
    private UnitViewSnapshotIndexMapper unitViewSnapshotIndexMapper;

    @Override
    public List<UnitViewSnapshotIndexVO> queryAll() {
        return unitViewSnapshotIndexMapper.dos2vos(unitViewSnapshotIndexDAO.queryAll());
    }

    @Override
    public void save(UnitViewSnapshotIndexVO unitViewSnapshotIndexVO) {
        // TODO 日志记录
        if (doInsert(unitViewSnapshotIndexVO)) {
            UnitViewSnapshotIndexDO insert = unitViewSnapshotIndexMapper.vo2do(unitViewSnapshotIndexVO);
            unitViewSnapshotIndexDAO.insert(insert);
        } else {
            unitViewSnapshotIndexDAO.update(unitViewSnapshotIndexMapper.vo2do(unitViewSnapshotIndexVO));
        }
    }

    @Override
    public UnitViewSnapshotIndexVO queryById(String id) {
        return unitViewSnapshotIndexMapper.do2vo(unitViewSnapshotIndexDAO.queryOneById(id));
    }

    @Override
    public PageList<UnitViewSnapshotIndexVO> queryPage(UnitViewSnapshotIndexVO unitViewSnapshotIndexVO, int pageNum, int pageSize) {
        PageList<UnitViewSnapshotIndexDO> pageQuery = unitViewSnapshotIndexDAO.pageQuery(unitViewSnapshotIndexMapper.vo2do(unitViewSnapshotIndexVO), pageNum, pageSize);
        return new PageList<>(unitViewSnapshotIndexMapper.dos2vos(pageQuery.getData()), pageQuery.getPaginator());

    }

    @Override
    public UnitViewSnapshotIndexVO queryBySystemUuidAndUseCaseUuid(String systemUuid, String useCaseUuid) {
        return unitViewSnapshotIndexMapper.do2vo(unitViewSnapshotIndexDAO.queryBySystemUuidAndUseCaseUuid(systemUuid, useCaseUuid));
    }
}
